package y23.May;

import java.security.SecureRandom;
import java.util.Random;
import java.util.Scanner;

public class Test5 {
    public static void main(String[] args) {
        Random random = new Random();
        int num = random.nextInt(100);
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你要猜的数字");
        int i = random.nextInt(100);
        int count = 0;
        while(i != num){
            System.out.println(i);
             if (i < num) {
                System.out.println("很抱歉，猜小了");
                int min = i;
                i = small(i,min);
            }else {
                System.out.println("很抱歉，猜大了");
                int max = i;
                i = big(i,max);
            }
            System.out.println("请重新输入你要猜的数字");
            count++;
        }
        if(i == num){
            System.out.println(i);
            System.out.println("恭喜你猜对了");
            System.out.println("你猜了"+count+"次");
        }
    }
    public static int random1(){

        SecureRandom random = new SecureRandom();
        return random.nextInt(100);
    }
    public static int big(int i,int max){
        int n = 0;
        n = random1();
        while(n > i&&n < max){
            n = random1();
        }
        return n;
    }

    public static int small(int i,int min){
        int n = 0;
        n = random1();
        while(n < i&&n > min){
            n = random1();
        }
        return n;
    }

}
